import request from '@/utils/request';
import { PageResponse } from '@/interface/pages';

/**
 * 获取分页列表
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getGoodsList = (params: API.goods.PageListDto) => {
  return request<PageResponse<API.goods.EntitySchema[]>>({
    url: '/admin/goods',
    method: 'get',
    params
  });
};

/**
 * 详情
 *
 * @param id
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getGoodsDetail = (ownId: string) => {
  return request<API.goods.EntitySchema>({
    url: `/admin/goods/${ownId}`,
    method: 'get'
  });
};

/**
 * 创建
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const createGoods = (data: API.goods.EntityDto) => {
  return request({
    url: `/admin/goods`,
    method: 'post',
    data
  });
};

/**
 * 编辑
 *
 * @param id
 * @param data
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateGoods = (ownId: string, data: any) => {
  return request({
    url: `/admin/goods/${ownId}`,
    method: 'put',
    data
  });
};

/**
 * 修改状态
 *
 * @param id
 * @param state
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateSwitch = (
  ownId: string,
  data: { isUp?: boolean; state?: boolean }
) => {
  return request({
    url: `/admin/goods/switch/${ownId}`,
    method: 'put',
    data
  });
};
